import originJSONP from 'jsonp';

export default function jsonp(url,data,option) {
  url += (url.indexOf('?')<0?'?':'&')+param(data);
  return new Promise((resolve, reject) => {
    originJSONP(url,option,(err,data)=>{
      if(!err){
        resolve(data);
      }else{
        reject(err);
      }
    })
  })
}

function param (data) {
  let url = '';
  for(var d in data){
    let value = data[d] !== undefined? data[d]:'';
    url += `&${d}=${encodeURIComponent(value)}`;
  }
  return url?url.substring(1) :'';
}
